const orm = require('elasticsearch-orm');
var esIndex:any = null;
function es_factory (params: any):Promise<any> {
    return new Promise((resolve, reject)=>{
        const instance = orm({
            'domain':params.domain,
            'port':params.port
        });
        instance.on('connected',async () =>{
            console.log('连接成功');
            esIndex = instance.register('index',{
            'index':'index',
            'type':'_doc'
            },{
            'number_of_shards': 5,
            'number_of_replicas': 1
            });
            const state = await esIndex.state();
            const result = await esIndex.analyze('我爱北京天安门','ik_max_word');
            console.log(result);
            resolve(esIndex);
        });
        instance.on('error',(e) =>{
            reject(e);
        });
    });
};
export default es_factory;